package day230510;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/5/10 17:17
 * 最长公共子序列
 */
public class Main02 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNext()) {
            String s1 = scan.next();
            String s2 = scan.next();
            int result = getLengthOfTheLongestCommonSubsequence(s1, s2);
            System.out.println(result);
        }
        scan.close();
    }

    // 获取最长公共子序列的长度
    private static int getLengthOfTheLongestCommonSubsequence(String s1, String s2) {
        // dp[i][j] 表示以 s1[i], s2[j] 结尾的最长公共子序列的长度
        // 如果 s1[i] == s2[j], 则 dp[i][j] = dp[i-1][j-1] + 1
        // 如果 s1[i] != s2[j], 则 dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        int[][] dp = new int[s1.length() + 1][s2.length() + 1];
        for (int i = 1; i <= s1.length(); i++) {
            for (int j = 1; j <= s2.length(); j++) {
                if (s1.charAt(i-1) == s2.charAt(j-1)) {
                    dp[i][j] = dp[i-1][j-1] + 1;
                } else {
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
        return dp[s1.length()][s2.length()];
    }
}
